package com.ityang.hhhh.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;


/**
 * 发送验证码
 */

public class MailUtils {

    public JavaMailSenderImpl JavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.163.com");
        mailSender.setUsername("yyuqian0206@163.com");
        mailSender.setPassword("FYTEQJZTBLVWJPCV");
        return mailSender;
    }
    //

   /* @Autowired
    private static JavaMailSender javaMailSender;*/

    //发送人
    private static String form = "yyuqian0206@163.com";
    //接收人
   // private static String to = "";
    //标题
    private static String  subject = "修改密码";
    //正文内容
    private static  String context1 = "【ityang】验证码为：";
    //正文内容
    private  static String context2 = "。如非本人操作，请忽略此信息";
    public void send(String code, String to){
        JavaMailSenderImpl javaMailSender = JavaMailSender();
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(form+"(剪易)");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(context1+code+context2);
        javaMailSender.send(message);
    }
}
